/****************************************************************************
 * taskapp
 * Tested MCU 
 * Owner : apleilx
 * **************************************************************************/
#include "dwinapp.h"
#include "mbinputdatacfg.h"
#include "appcfg.h"
#include "pincfg.h"
#include "tempctr.h"
#include "tempctrlib.h"
#include "mbport_00.h"
#include "systimer.h"
#include "systask.h"

void dwinSysKeyHandle(void);
void ExtEepSave(uint16_t EepAddr, uint16_t Data);


/*****************************************************************************//*!
*
* @brief   dwin main.
*                
* @param   none
*
* @return  none
*
* @ Pass/ Fail criteria: none
*****************************************************************************/
void dwinSysHandle(void){
  
    
    if(0 != mmb_cmd_ready_num(dwin_port))
        return;
    
    if(dwopt.PageKeepTimeCnt < 10)
        return;
		
    dwinSysKeyHandle();
    
    
}


/*****************************************************************************//*!
*
* @brief   Key handle.
*                 
* @param   none
*
* @return  none
*
* @ Pass/ Fail criteria: none
*****************************************************************************/
void dwinSysKeyHandle(){
   

  
    if((gudingKAI))
    {
		   //	ParTab[PAR_FUN_upt_POS].iVal=0;
           //无输出变为输出
            if((0 == sys_st.led_out.ctr_st)&&(bTingZhiRun))
            {
                SpeakerNoticeTimeCnt=1;
                sys_st.led_out.ctr_st = 1;
            }
            //输出变为暂停
            else if((1 == sys_st.led_out.ctr_st)&&(!bTingZhiRun))
            {
                sys_st.led_out.ctr_st = 2;
                
            }
            //暂停变为输出
            else if((2 == sys_st.led_out.ctr_st)&&(bTingZhiRun))
            {
                sys_st.led_out.ctr_st = 1;
            }
    }
    else
    {
        sys_st.led_out.ctr_st = 0;
    }
  
   
           //停止
    if((dwopt.pv_read[8].byte.HB != dwopt.pv_read_old[8].byte.HB)&&(dwopt.pv_read[8].byte.HB!=0x7F))
    {
				sys_st.led_out.ctr_st=0;
         gudingKAI=0;
         bTingZhiRun=0;
			   dwinPageSet(3);
    }
		if((sys_st.led_out.ctr_st==0)&&(gudingKAI==0))
  {
     
      if((dwopt.pv_read[6].uVal != dwopt.pv_read_old[6].uVal) && (dwopt.pv_read[6].uVal != 0x7F7F))//辐照剂量
      {
										bSUBXJ=1;
                            if(dwopt.pv_read[6].uVal != ParTab[PAR_USER_PK1_POS].iVal)
                            {
                                ParTab[PAR_USER_PK1_POS].iVal = dwopt.pv_read[6].uVal;
                                ExtEepSave(PAR_USER_PK1_POS * 2, ParTab[PAR_USER_PK1_POS].iVal);
                            }
      }
			
                    {
                        if(ParTab[PAR_USER_PK1_POS].iVal> 501)
                        {
                           ParTab[PAR_USER_PK1_POS].iVal= 500;
                        }
                    }
                   
                    {
                        if(ParTab[PAR_USER_PK1_POS].iVal<= 0)
                        {
                            ParTab[PAR_USER_PK1_POS].iVal= 0;
                        }
                    } 
  }    

}

/*****************************************************************************//*!
*
* @brief   user entry init.
*                 
* @param   none
*
* @return  none
*
* @ Pass/ Fail criteria: none
*****************************************************************************/
void dwinSysEntryInit(void){
   
}
